package boogui.member;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;

import boogui.movie.MovieReserveService;
import boogui.movie.MovieVO;
import java.awt.Toolkit;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class S_ReservationInfoDialog extends JDialog {
	
	private static UserVO u = null;
	private MovieReserveService mrs = null;

	private final JPanel contentPanel = new JPanel();
	private JTable table;

	/**
	 * Launch the application.
	 */
/*	public static void main(String[] args) {
		try {
			S_ReservationInfoDialog dialog = new S_ReservationInfoDialog(new UserVO());
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}*/

	/**
	 * Create the dialog.
	 */
	public S_ReservationInfoDialog(UserVO u) {
		setModal(true);
		setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/menu/rcheck.png")));		
		mrs = new MovieReserveService();
		setTitle("예매 정보 확인");
		setBounds(100, 100, 700, 300);
		setLocationRelativeTo(null);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS));
		{
			JLabel lblNewLabel = new JLabel("예매 정보 확인");
			lblNewLabel.setFont(new Font("맑은 고딕", Font.BOLD, 16));
			lblNewLabel.setBorder(new EmptyBorder(10, 10, 10, 10));
			contentPanel.add(lblNewLabel);
		}
		{
			JScrollPane scrollPane = new JScrollPane();
			contentPanel.add(scrollPane);
			{
				DefaultTableModel model = new DefaultTableModel() {
					@Override
					public boolean isCellEditable(int row, int column) {
						return false;
					}
				};
				String title[] = {"제목","날짜","시간","영화관","좌석"};
				model.setColumnIdentifiers(title);
				for (MovieVO m : mrs.readReservation(u)) {
					model.addRow(new String[] {m.getMovtitle(), m.getSdate().substring(0, 10),m.getStime(), m.getCinename() + m.getTheater(),m.getSeat()});
				}
				
				table = new JTable(model);
				
				scrollPane.setViewportView(table);
			}
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton cancelButton = new JButton("닫 기");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						setVisible(false);
						dispose();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
		setVisible(true);
	}

}
